package com.meng.system.service.impl.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meng.system.domain.dto.SysJobDTO;
import com.meng.system.mapper.job.JobMapper;
import com.meng.system.service.job.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Mr.Still
 * @version 1.0.0
 * @date 2021-06-13 00:13
 **/
@Service
public class JobServiceImpl implements JobService {

    @Autowired
    private JobMapper jobMapper;

    @Override
    public boolean addRunJob(SysJobDTO job) {
        return jobMapper.insert(job) > 0;
    }

    /**
     * 获取所有job信息
     */
    @Override
    public Page<SysJobDTO> findJobMsgList(Integer status,Integer pageNum,Integer pageSize) {
        Page<SysJobDTO> page = new Page<>(pageNum,pageSize);
        if (status != null){
            QueryWrapper<SysJobDTO> wrapper = new QueryWrapper<>();
            wrapper.eq("job_status",status);
            return jobMapper.selectPage(page, wrapper);

        } else {
            return  jobMapper.selectPage(page,null);
        }
    }

    @Override
    public boolean deleteSysJobById(Integer jobId) {
        return jobMapper.deleteById(jobId) > 0;
    }

    @Override
    public boolean updateJob(SysJobDTO job) {
        return jobMapper.updateById(job) > 0;
    }
}
